// 1. 导入mongoose
const mongoose = require('./01-2-mongoose使用流程');
// 2. 连接数据库
// 3. 创建连接回调 connection.on("open",callback)
    // 5. 创建文档解构 new mongoose.Schema()

const movieSchema = new mongoose.Schema({
    name:String,
    time:Number,
    score:Number,
    boxOffice:Number,
    type:String
})
    // 6. 创建模型对象 mongoose.model()
const movieModel = mongoose.model('movies',movieSchema);
    // 7. 批量插入 model.insertMany({},callback)
   let res = movieModel.insertMany([
        {
            name:"让子弹飞",
            time:130,
            score:10,
            boxOffice:50,
            type:"姜氏幽默"
        },
        {
            name:"邪不压正",
            time:130,
            score:8.0,
            boxOffice:10,
            type:"姜氏幽默"
        }
    ],(err,data)=>{
        if(err){
            console.log("失败");
        }else{
            console.log(data);
        }
    })

